//
//  DownMusicModel.m
//  MiBaoTu
//
//  Created by 邹奥 on 16/9/25.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "DownMusicModel.h"

@implementation DownMusicModel

//长度转换成大小
- (float)calculateFileSizeInUnit:(unsigned long long)contentLength
{
    if (contentLength > pow(1024, 3)) {
        //G
        return (float)(contentLength / (float)pow(1024, 3));
    }
    else if (contentLength > pow(1024, 2)) {
        return (float)(contentLength / (float)pow(1024, 2));
    }
    else if (contentLength > pow(1024, 1)) {
        return (float)(contentLength / (float)pow(1024, 1));
    } else {
        return (float)contentLength;
    }
}


- (NSString *)calculateUnit:(unsigned long long)contentLength
{
    if(contentLength >= pow(1024, 3)){
        return @"GB";
    }
    else if(contentLength >= pow(1024, 2)) {
        return @"MB";
    }
    else if(contentLength >= 1024) {
        return @"KB";
    } else {
        return @"B";
    }
}

- (void)encodeWithCoder:(NSCoder *)aCoder //将属性进行编码
{
    [aCoder encodeObject:self.url forKey:@"url"];
    [aCoder encodeObject:self.fileName forKey:@"fileName"];
    [aCoder encodeInteger:self.totalLength forKey:@"totalLength"];
    [aCoder encodeObject:self.totalSize forKey:@"totalSize"];
    [aCoder encodeObject:self.musicID forKey:@"musicID"];
    [aCoder encodeObject:self.musicType forKey:@"musicType"];
    [aCoder encodeObject:self.userID forKey:@"userID"];
    [aCoder encodeObject:self.content forKey:@"content"];
    [aCoder encodeObject:self.picUrl forKey:@"picUrl"];
    [aCoder encodeObject:self.date forKey:@"date"];
    [aCoder encodeObject:self.userPic forKey:@"userPic"];
    [aCoder encodeObject:self.userNick forKey:@"userNick"];
    [aCoder encodeObject:self.size forKey:@"size"];
    [aCoder encodeObject:self.isDowning forKey:@"isDowning"];
}

- (id)initWithCoder:(NSCoder *)aDecoder //将属性进行解码
{
    self = [super init];
    if (self) {
        self.url = [aDecoder decodeObjectForKey:@"url"];
        self.fileName = [aDecoder decodeObjectForKey:@"fileName"];
        self.totalLength = [aDecoder decodeIntegerForKey:@"totalLength"];
        self.totalSize = [aDecoder decodeObjectForKey:@"totalSize"];
        self.musicID = [aDecoder decodeObjectForKey:@"musicID"];
        self.musicType = [aDecoder decodeObjectForKey:@"musicType"];
        self.userID = [aDecoder decodeObjectForKey:@"userID"];
        self.content = [aDecoder decodeObjectForKey:@"content"];
        self.picUrl = [aDecoder decodeObjectForKey:@"picUrl"];
        self.date = [aDecoder decodeObjectForKey:@"date"];
        self.userPic = [aDecoder decodeObjectForKey:@"userPic"];
        self.userNick = [aDecoder decodeObjectForKey:@"userNick"];
        self.size = [aDecoder decodeObjectForKey:@"size"];
        self.isDowning = [aDecoder decodeObjectForKey:@"isDowning"];
    }
    return self;
}

@end
